import { forIn } from 'lodash-es'

// 生成随机字符串
export function generateRandomString(length: number) {
  const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
  let result = ''
  for (let i = 0; i < length; i++) {
    var randomIndex = Math.floor(Math.random() * characters.length)
    result += characters.charAt(randomIndex)
  }
  return result
}

// table的rules
export const requiredRules = (requiredDict: any = {}, conf: any) => {
  let { addText = '不能为空', trigger = 'blur' } = conf || {}
  const rules: any = {}
  forIn(requiredDict, (value: any, key: any) => {
    rules[key] = { required: true, message: `${value}${addText}`, trigger }
  })
  return rules
}

// 打招呼
export const hello = (uname: string) => {
  const h = new Date().getHours()
  let str = `哦亲爱的 ${uname} ，`
  if (h <= 4 || h >= 23) str += '夜深了，早些歇息吧。'
  else if (h >= 5 && h <= 11) str += '早上好，今天也是元气满满的一天呢。'
  else if (h >= 12 && h <= 15) str += '中午好，今天午休了吗？'
  else if (h >= 16 && h <= 19) str += '下午好，晚上吃点啥呢？'
  else if (h >= 19 && h <= 22) str += '晚上好，要一起去看月亮嘛。'
  return str
}
